package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.SpeedLimitAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Classname SpeedLimitAttrLinkHandler
 * @Description 限速（M）=其他，展示 可填带宽速率(M)，必填
 * @Author zhang.song
 * @Date 2021-02-23 11:56
 */
@Service
@AttrHandler(SpeedLimitAttrHandler.class)
public class SpeedLimitAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        if("2_0000005".equals(attr.getFieldName())) {
            // SDH（60000017）限速=其他，显示 限速速率（2_0000098），show_type 改为 M
            KiteAttr speed = inst.getAttr("2_0000098");
            if ("1_0000116".equals(attr.getValue())) {
                if (Objects.nonNull(speed)) {
                    speed.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_M);
                    speed.setIsNull(KeyConsts.IFTRUE_F);
                }
            } else {
                speed.setValue("");
                speed.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
                speed.setIsNull(KeyConsts.IFTRUE_T);
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
